<?php

namespace yunj\enum;

use yunj\Enum;

final class TipsTemplet extends Enum {

    const NOT_FOUND = 404;

    const LOGOUT = 200;

    const OVERDUE = 401;

    const NO_AUTH = 403;

    const TIMEOUT = 408;

    const ERROR = 500;

    public static function options(): array {
        $options = [
            self::NOT_FOUND => [
                'msg' => '不好意思，您访问的页面不存在~',
                'action' => '__BACK__',
            ],
            self::LOGOUT => [
                'msg' => '您已成功退出平台！',
                'action' => '__LOGIN__',
            ],
            self::OVERDUE => [
                'msg' => '不好意思，您的登录已过期~',
                'action' => '__LOGIN__',
            ],
            self::NO_AUTH => [
                'msg' => '不好意思，您无权限访问...',
                'action' => '__BACK__',
            ],
            self::TIMEOUT => [
                'msg' => '不好意思，您的操作已超时，请重新登录~',
                'action' => '__LOGIN__',
            ],
            self::ERROR => [
                'msg' => '系统内部异常，稍后重试~',
                'action' => '__BACK__',
            ],
        ];
        return $options;
    }

    public static function assignData() {
        $param = input('get.') ?: [];
        $templet = isset($param['templet']) && self::isExist($param['templet']) ? $param['templet'] : self::ERROR;
        $templetAttr = self::attr($templet);
        $assignData = ["code" => $templet]+$templetAttr;
        if (isset($param['msg'])) $assignData['msg'] = $param['msg'];
        if ($assignData['code'] == 200) $assignData['msg'] .= '当前时间：' . date('Y-m-d H:i:s');
        return $assignData;
    }

}